package com.ruicar.afs.cloud.workflow.greatwall.dto;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumDeserializer;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumSerializer;
import com.ruicar.afs.cloud.workflow.greatwall.enums.GwtMsgType;
import com.ruicar.afs.cloud.workflow.greatwall.enums.GwtObjectCode;
import lombok.Data;

import java.text.MessageFormat;

@Data
public class GwtRequest {
    @JSONField(name = "ServiceId")
    @JsonProperty("ServiceId")
    private String serviceId;

    @JSONField(name = "DataId")
    @JsonProperty("DataId")
    private String dataId;


    @JSONField(name = "MsgType", serializeUsing = AfsEnumSerializer.class, deserializeUsing = AfsEnumDeserializer.class)
    @JsonProperty("MsgType")
    @JsonSerialize(using = AfsEnumSerializer.class)
    @JsonDeserialize(using = AfsEnumDeserializer.class)
    private GwtMsgType msgType;

    @JSONField(name = "ObjectCode", serializeUsing = AfsEnumSerializer.class, deserializeUsing = AfsEnumDeserializer.class)
    @JsonSerialize(using = AfsEnumSerializer.class)
    @JsonDeserialize(using = AfsEnumDeserializer.class)
    @JsonProperty("ObjectCode")
    private GwtObjectCode objectCode;

    @JSONField(name = "Body")
    @JsonProperty("Body")
    private String body;

    public String getLockKey() {
        return MessageFormat.format("{0}-{1}", this.serviceId, this.dataId);
    }

    @Override
    public String toString() {
        return "GwtRequest{" +
                "serviceId='" + serviceId + '\'' +
                ", dataId='" + dataId + '\'' +
                ", msgType=" + msgType +
                ", objectCode=" + objectCode +
                ", body='" + body + '\'' +
                '}';
    }
}
